package com.youbug.system.controller;


import com.youbug.common.vo.QueryVo;
import com.youbug.system.entity.Generator;
import com.youbug.system.service.IGeneratorService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youbug.system.vo.GenerateInfo;
import org.springframework.web.bind.annotation.*;
import com.youbug.common.vo.R;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * VIEW 前端控制器
 * </p>
 *
 * @author youbug
 * @since 2023-12-27
 */
@RestController
@RequestMapping("/generator")
public class GeneratorController {
@Autowired
private IGeneratorService generatorService;

    @PostMapping("/getGeneratorPage")
    public R<IPage<Generator>> getGeneratorPage(@RequestBody QueryVo<Generator> queryVo){

        IPage<Generator> generators = generatorService.getGeneratorPage(queryVo);

        return R.ok(generators);
    }

    @GetMapping("/getGeneratorById/{id}")
    public R<Generator> getMenusForRole(@PathVariable Integer id){

        Generator generator = generatorService.getById(id);

        return R.ok(generator);
    }

    @PostMapping("/add")
    public R<Boolean> add(@RequestBody Generator generator){

        boolean save = generatorService.save(generator);

        return  R.ok(save);
    }

    @PostMapping("/update")
    public R<Boolean> update(@RequestBody Generator generator){

        boolean update = generatorService.updateById(generator);

        return  R.ok(update);
    }

    @GetMapping("/delete/{id}")
    public R<Boolean> delete(@PathVariable Integer id){

        boolean remove = generatorService.removeById(id);

        return  R.ok(remove);
    }

    @PostMapping("/doGenerator")
    public R<Boolean> doGenerator(@RequestBody GenerateInfo generateInfo){

        boolean generated = generatorService.generate(generateInfo);

        return  R.ok(generated);
    }

}

